package com.coder520.sync_learning.demo.ThreadPool01;

import java.util.concurrent.TimeUnit;

public interface DenyPolicy {

    void reject(Runnable runnable,ThreadPool threadPool);

    class DiscardDenyPolicy implements DenyPolicy{
        @Override
        public void reject(Runnable runnable, ThreadPool threadPool) {
            // do sth
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    //这个拒绝的策略会像任务的提交者抛出异常
    class AbortDenyPolicy implements  DenyPolicy{
        @Override
        public void reject(Runnable runnable, ThreadPool threadPool) {
            if (!threadPool.isShutdown()){
                runnable.run();
            }
        }
    }


}
